package com.ize.controller.admin;


import com.ize.entity.dto.AdminLoginDto;
import com.ize.entity.dto.DoctorInfoUpdateDto;
import com.ize.entity.dto.UpdatePaasDto;
import com.ize.entity.pojo.Doctor;
import com.ize.entity.vo.AdminLoginVo;
import com.ize.result.Result;
import com.ize.service.DoctorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.URL;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin")
@Slf4j
@Api(tags = "医生模块", value = "管理员相关接口")
@RequiredArgsConstructor
public class doctorController {

    private final DoctorService doctorService;


    /**
     * 医生注册
     * @param adminLoginDto
     * @return
     */
    @PostMapping("/register")
    @ApiOperation("医生注册")
    public Result register(@RequestBody AdminLoginDto adminLoginDto) {
        log.info("注册参数adminLoginDto:{}", adminLoginDto);
        doctorService.register(adminLoginDto);
        return Result.success();
    }


    /**
     * 医生登录
     * @param adminLoginDto
     * @return
     */
    @PostMapping("/login")
    @ApiOperation("医生登录")
    public Result login(@RequestBody AdminLoginDto adminLoginDto) {
        log.info("登录参数adminLoginDto:{}", adminLoginDto);
        AdminLoginVo user = doctorService.login(adminLoginDto);
        return Result.success(user);
    }

    /**
     * 获取用户信息
     * @return
     */
    @GetMapping("/userInfo")
    @ApiOperation("获取医生信息")
    public Result<Doctor> getDoctorById() {
        Doctor doctor = doctorService.getDoctorById();
        return Result.success(doctor);
    }


    @PutMapping("/update")
    @ApiOperation("修改医生信息")
    public Result update(@RequestBody DoctorInfoUpdateDto doctorInfoUpdateDto) {
        log.info("修改信息:{}", doctorInfoUpdateDto);
        doctorService.updateById(doctorInfoUpdateDto);
        return Result.success();
    }

    //更新用户头像
    @PatchMapping("/updateAvatar")
    @ApiOperation("用户头像更新")
    public Result updateavater(@RequestParam @URL String avatarUrl){
        doctorService.updateAvatar(avatarUrl);
        return Result.success();
    }


    /**
     * 修改密码
     * @param updatePaasDto
     * @return
     */
    @PutMapping("/updatePass")
    @ApiOperation("修改密码")
    public Result updatePass(@RequestBody UpdatePaasDto updatePaasDto){
        log.info("前段传过来的密码updatePaasDto:{}", updatePaasDto);
        doctorService.updatePass(updatePaasDto);
        return Result.success();
    }


}
